package com.css.fxfzaqbz.modules.data.repository.impl;

import com.css.fxfzaqbz.modules.data.repository.DistrictBoundaryRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class DistrictBoundaryRepositoryImpl implements DistrictBoundaryRepository {
    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    @Override
    public String getExtent(List<String> codes) {
        String codess = StringUtils.join(codes, "','");
        String sql="select ST_extent(a.geom) from (select st_union(st_geomfromtext(coordinate,4490)) as geom from district_boundary where code in ('"+codess+"')) a";
        String s = jdbcTemplate.queryForObject(sql, String.class);
        return s;
    }

    @Override
    public String getcenter(List<String> codes) {
        String codess = StringUtils.join(codes, "','");
        String sql="select ST_AsText(ST_Centroid(ST_extent(a.geom))) from (select st_union(st_geomfromtext(coordinate,4490)) as geom from district_boundary where code in ('"+codess+"')) a";
        String s = jdbcTemplate.queryForObject(sql, String.class);
        return s;
    }
}
